package edu.vt.ece3574.ninjatag;

import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Binder;
import android.os.Bundle;
import android.os.IBinder;
import android.widget.Toast;

public class LocationService extends Service {

	 public class LocalBinder extends Binder {
	        LocationService getService() {
	            return LocationService.this;
	        }
	    }

	public void onCreate() {
		
		Toast.makeText(getApplicationContext(), "Location Service Started...", Toast.LENGTH_SHORT).show();	
	    
		 // Acquire a reference to the system Location Manager
	    LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);

	    // Define a listener that responds to location updates
	    LocationListener locationListener = new locationListener();
	      
	    // Register the listener with the Location Manager to receive location updates
	    locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);
		locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener);
	}
	
	@Override
	public IBinder onBind(Intent arg0) {
		// TODO Auto-generated method stub
		return null;
	}
	
	public class locationListener implements LocationListener {

		// Called when a new location is found by the network location provider.
		public void onLocationChanged(Location location) {
			Toast.makeText(getApplicationContext(), "Location Changed", Toast.LENGTH_SHORT).show();	
		}

	    public void onStatusChanged(String provider, int status, Bundle extras) {
	    	
	    }

	    public void onProviderEnabled(String provider) {
	    	Toast.makeText(getApplicationContext(), "Gps Enabled", Toast.LENGTH_SHORT).show();	
	    }


		public void onProviderDisabled(String provider) {
	    	Toast.makeText(getApplicationContext(), "Gps Disabled", Toast.LENGTH_SHORT ).show();
	    }
	}

	//-----External Service Getters / Setters-----
	public int getLat() {
		// TODO Auto-generated method stub
		return 0;
	}

	public int getLon() {
		// TODO Auto-generated method stub
		return 0;
	}
}